package com.cmict.data.form.api.service.impl;

import com.cmict.data.framework.common.pojo.PageResult;
import com.cmict.data.framework.tenant.core.aop.TenantIgnore;
import com.cmict.data.form.api.dal.dataobject.info.MdColumnsDO;
import com.cmict.data.form.api.dal.mysql.info.MdColumnsMapper;
import com.cmict.data.form.api.entity.vo.MdColumnsExportReqVO;
import com.cmict.data.form.api.entity.vo.MdColumnsPageReqVO;
import com.cmict.data.form.api.service.MdColumnsService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * 字段信息 Service 实现类
 *
 * @author 系统管理员
 */
@Service
@Validated
public class MdColumnsServiceImpl implements MdColumnsService {

    @Resource
    private MdColumnsMapper mdColumnsMapper;

    @DS("slave")
    @Override
    public MdColumnsDO getMdColumns(String id) {
        return mdColumnsMapper.selectById(id);
    }

    @Override
    @DS("slave")
    @TenantIgnore
    public List<MdColumnsDO> getMdColumnsByTableId(String tableId) {
        tableId = tableId.substring(tableId.lastIndexOf(",")+1);
        QueryWrapper<MdColumnsDO> qw = new QueryWrapper<>();
        qw.lambda().eq(MdColumnsDO::getTableId, tableId);
        return mdColumnsMapper.selectList(qw);
    }

    @DS("slave")
    @Override
    public List<MdColumnsDO> getMdColumnsList(Collection<String> ids) {
        return mdColumnsMapper.selectBatchIds(ids);
    }

    @DS("slave")
    @Override
    public PageResult<MdColumnsDO> getMdColumnsPage(MdColumnsPageReqVO pageReqVO) {
        return mdColumnsMapper.selectPage(pageReqVO);
    }

    @DS("slave")
    @Override
    public List<MdColumnsDO> getMdColumnsList(MdColumnsExportReqVO exportReqVO) {
        return mdColumnsMapper.selectList(exportReqVO);
    }

}
